package com.shop.impl;

/**
 * Created with IntelliJ IDEA.
 * User: 王瑞文
 * Date: 2020/9/6
 * Time: 16:07
 * To change this template use File | Settings | File Templates.
 * Description:
 */
import com.alibaba.fastjson.JSONObject;
import com.shop.base.BaseApiService;
import com.shop.base.BaseResponse;
import com.shop.oss.ossService;
import com.shop.utils.AliYunOssUtil;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.Calendar;

@RestController
public class OssServiceImpl extends BaseApiService implements ossService {

    @Override
    public BaseResponse<JSONObject> fileUpload(MultipartFile file) {
        //上传文件
        long timeInMillis = Calendar.getInstance().getTimeInMillis();
        try {
            InputStream inputStream = file.getInputStream();
            String s = AliYunOssUtil.UploadToAliyun(timeInMillis + file.getName(), inputStream, "png");
            return setResultSuccess(s);
        } catch (IOException e) {
            e.printStackTrace();
            return setResultError("上传失败");
        }

    }
}
